$(function () {
    isLogin();
});

function isLogin() {
    let username = sessionStorage.getItem("username");
    if (username == null) {
        location.href = "/login.html";
    }
}

function myAjax(url, data, type) {
    let result = null;
    data.loginName = sessionStorage.getItem("username");
    // let da = {loginName: sessionStorage.getItem("username")};
    //两个json对象合并成一个对象Object.assign(da, data)
    $.ajax({
        url: url,
        data: data,
        type: type,
        async: false,
        dataType: 'json',
        success: function (data) {
            console.log(data, 22);
            result = data;
            if (data.code == -1) {
                window.open("/login.html", "_parent");
            }
        }
    });
    return result;
}

function myFileAjax(url, data, type) {
    let result = null;
    $.ajax({
        url: url,
        data: data,
        type: type,
        async: false,
        dataType: 'json',
        contentType: false,
        processData: false,
        success: function (data) {
            console.log(data, 22);
            result = data;
            if (data.code == -1) {
                window.open("/login.html", "_parent");
            }
        }
    });
    return result;
}
